package indi.yuluo.controller;

import indi.yuluo.service.CodeService;
import indi.yuluo.vo.Msg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: yuluo
 * @CreateTime: 2022-08-16  23:17
 * @Description: TODO
 */

@RestController
@Slf4j
@RequestMapping(value = "/code")
@Api("code相关控制器")
public class CodeController {

    @Resource
    private CodeService codeService;

    @GetMapping(value = "/templates")
    @ApiOperation(value = "获取代码模板信息", httpMethod = "GET")
    public Msg getCodeTemplate() {

        boolean flag = false;

        Map<String, String> resMap = codeService.getCodeTemplates();

        if (resMap != null) {
            flag = true;
        }

        return flag ? Msg.success().add("codeTemplates", resMap) : Msg.fail().add("error", "获取代码模板信息失败！");
    }

    @GetMapping("/getCodeType")
    @ApiOperation(value = "获取语言种类信息", httpMethod = "GET")
    public Msg getCodeType() {

        boolean flag = false;

        List<String> res = codeService.getCodeType();

        if (res != null) {
            flag = true;
        }

        return flag ? Msg.success().add("codeType", res) : Msg.fail().add("error", "获取失败！");

    }

}
